#!/bin/bash

if [ $# == 0 ]; then
	echo "Usage:"
	echo "./nfw <z lens> <z source> <nfw mass> <nfw c>"
        echo
	exit 1
fi

zl=$1
zs=$2
mass=$3
c=$4

# Clean environment
./clean.sh

ksmod="ksmod"

kappas=$($ksmod $zl $zs $mass $c 0.25 0.75 | cut -f1 | cut -d' ' -f2)
tmp=$($ksmod $zl $zs $mass $c 0.25 0.75 | cut -f2 | cut -d' ' -f2)
xsL=$(echo "$tmp * 60.0" | bc -l)


eL=0.4
thetaL=0.0

gridhi=$(echo "2.0*$xsL" | bc -l)



echo "kappas=$kappas"
echo "xsL=$xsL"
echo "Warning: gridhi is set to $gridhi"

echo "
set plotmode=2
set gridhi1=$gridhi
set xtol = 0.0000000001
set crittol = 0.001
set inttol = 0.001
set maxlev = 4
startup 1 1
nfw $kappas 0 0 $eL $thetaL 0 0 $xsL 0 0 
0 0 0 0 0 0 0 0 0 0


#makekapmap kappa_map.fits 3 kappa_map.range -$gridhi $gridhi 500 -$gridhi $gridhi 500

plotcrit cc.dat
plotgrid grid.dat

#setsource 1
#  sersic 1.0 0.0 0.0 0.0 0.0 0.03 0 0.5 macro
#  0 0 0 0 0 0 0 0
#SBmap2 -$gridhi $gridhi 500 -$gridhi $gridhi 500 1 arcs.fits 3

" > nfw.gl

gravlens nfw.gl > nfw.log

